<template>
<div>
    
    <el-card class="box-card">
  <div slot="header" class="clearfix">
    <span>添加区域</span>
  </div>


    <From :form="form">
      <el-form-item>
        <el-button type="primary" @click="onSubmit" :loading="loading">立即创建</el-button>
        <!-- <el-button>取消</el-button> -->
      </el-form-item>
    </From>
    </el-card>
  </div>
  
</template>

<script>
import From from "./From";
export default {
  data() {
    return {
       loading: false,
      //存放表单数据
      form: {
        cityId:'',
        cityName:'',
        //地区名称
        name:''
      }
    };
  },
  created(){
    //接收传过来的参数
    // this.form.cityId=this.$route.params.cityId
    // this.form.cityName=this.$route.params.cityName

    //跟上面写法一样  
    this.form={
      ...this.form,
      cityId:this.$route.params.cityId,
      cityName:this.$route.params.cityName,

    }
  },
  components: {
    From
  },
  methods: {
    async onSubmit() {
      let url = "/area/add";
      let data=this.form;
        try {
        this.loading=true
        let res = await this.$axios.post(url, data);
        this.$message({
          message: "添加区域成功",
          type: "success"
        });

          //设置跳转
        setTimeout(() => {
          //
          this.$router.push({
            path: "/area/list"
          });
        }, 1000);


      } catch (error) {}
      this.loading = false;    
    }
  }
};
</script>
<style>
.fond{
  font-size:13.5px
}
</style>